[phpunit 12] Add AllowMockObjectsWithoutExpectationsAttributeRector#619
Merged
TomasVotruba merged 3 commits intomainfrom Jan 28, 2026
Merged
[phpunit 12] Add AllowMockObjectsWithoutExpectationsAttributeRector#619TomasVotruba merged 3 commits intomainfrom
TomasVotruba merged 3 commits intomainfrom
Conversation
dd60750 to
7bc815c
Compare
51203a3 to
287fca2
Compare
e8e55ae to
85433d6
Compare
e0acb2e to
236d186
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PHPUnit 12 introduced requirement for mocks to be used or be stubs. There is quite common use case that breaks this assumption. Mock object defined in in
setUp()method, used in multiple test methods, but not defining expectations in all of them. Often these mocks are passed as arguments into anewservice defined insetUp()method as well.This will turn your PHPUnit run into list of NNNNNNs and make test hard to read and impossible to turn off. It seem something is broken, and it forces you to rewrite a lot of tests manually.
Since PHPUnit 12.5.2 you can add special attribute per tests to ignore this notice. More manual dumb work.
This rule automates this process by looking at:
MockObjectproperty? ✔️setUp()method? ✔️setUp()method or at least in 2 tests methods? - TODOThen adds the attribute there, as we obviously want to use the mock this way.
Any further checks we can automate? Keep them coming.